package app.client.collect.cartoon;

import java.util.List;

import app.client.collect.cartoon.entity.CartoonCollectEntity;
import cn.lily.com.file.excel.css.ExcelWriterStyle;
import cn.lily.com.file.excel.io.ExcelWriter;
import cn.lily.com.file.excel.spe.IExcelBorder;
import cn.lily.com.file.excel.spe.IExcelColor;

public class BaseCollectAnalyse {
	
	protected ExcelWriter writer;
	
	/**
	 * 创建Writer
	 */
	public void createWriter(){
		this.writer = new ExcelWriter("D:/export.xlsx");
		this.writer.inst();
	}
	
	/**
	 * 导出
	 * @param sheetName
	 * @param entitys
	 */
	public void export(String sheetName,List<CartoonCollectEntity> entitys){
		
		//添加Sheet
		this.writer.createSheet();
		this.writer.renameSheet(sheetName);
		
		ExcelWriterStyle titleStyle = new ExcelWriterStyle(this.writer);
		titleStyle.getCell().setCellAlign("center").setCellVetical("center").setBackGroundColor(IExcelColor.GREY_40_PERCENT);
		
		//添加标题
		this.writer.locateRow(0);
		
		this.writer.setCellValue(0, "动漫名称");
		this.writer.setColWith(0, 250);
		this.writer.setStyle(titleStyle);
		this.writer.setCellValue(1, "动漫季数");
		this.writer.setColWith(1, 100);
		this.writer.setStyle(titleStyle);
		this.writer.setCellValue(2, "动漫集数");
		this.writer.setColWith(2, 100);
		this.writer.setStyle(titleStyle);
		this.writer.setCellValue(3, "动漫年份");
		this.writer.setColWith(3, 100);
		this.writer.setStyle(titleStyle);
		this.writer.setCellValue(4, "动漫地区");
		this.writer.setColWith(4, 100);
		this.writer.setStyle(titleStyle);
		this.writer.setCellValue(5, "动漫状态");
		this.writer.setColWith(5, 100);
		this.writer.setStyle(titleStyle);
	
		int rowIdx = 1;
		for(CartoonCollectEntity entity:entitys){
			this.writer.locateRow(rowIdx);
			this.writer.setCellValue(0, entity.getCartoonName());
			this.writer.setCellValue(1, entity.getSeason());
			this.writer.setCellValue(2, entity.getCartoonNum()+"");
			this.writer.setCellValue(3, entity.getYear());
			this.writer.setCellValue(4, entity.getArea());
			this.writer.setCellValue(5, entity.getStatus());
			rowIdx++;
		}
		
	}
	
	public void save(){
		this.writer.write();
	}
	
	/**
	 * 释放
	 */
	public void free(){
		this.writer.free();
	}
}
